from django.db import models
from django.utils import timezone
from datetime import date
# Create your models here.
from AppBase.models import UserDict

#资源类别
class ResourceTypeDict(models.Model):#类型字典
    ID = models.AutoField(primary_key=True,verbose_name="序号")  # 自定义自增列
    Name = models.CharField(max_length=64, verbose_name="类型名称")
    class Meta:
        verbose_name=verbose_name_plural="资源分类"
    def __str__(self):
        return self.Name  # ，即返回对象的时候，返回它的Name属性值
#资源上传记录
class ResourceRecord(models.Model):
    ID = models.AutoField(primary_key=True)  # 自定义自增列
    Title=models.CharField(max_length=256,verbose_name="标题",default="未写标题")
    Abstract = models.TextField(verbose_name='简介', default='')
    Content = models.TextField(verbose_name='详细描述', default='')
    CoverChart=models.ImageField(upload_to='img',default="img/default.jpg")#封面图
    SourceFile = models.FileField(upload_to='sourcefiles', default='') #资源文件
    RecType = models.ForeignKey(ResourceTypeDict, on_delete=models.CASCADE,null=True)  # 用户删除 本表关联数据也会删除
    HotValue = models.IntegerField(default=0, verbose_name="下载次数")
    Creator = models.ForeignKey(UserDict, on_delete=models.CASCADE)  # 用户删除 本表关联数据也会删除
    CreateDatetime = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    class Meta:
        verbose_name=verbose_name_plural="资源上传记录"

#上传记录附带其他图片
class ResourcePic(models.Model):
    ID = models.AutoField(primary_key=True)  # 自定义自增列
    ResourceRec = models.ForeignKey(ResourceRecord, on_delete=models.CASCADE,null=True)
    Pic = models.ImageField(upload_to='pics', default="img/default.jpg")  # 封面图
    class Meta:
        verbose_name=verbose_name_plural="资源附带图片"

#用户下载记录
class UserDownLoadRecord(models.Model):
    ID = models.AutoField(primary_key=True)  # 自定义自增列
    ResourceRec = models.ForeignKey(ResourceRecord, on_delete=models.CASCADE, null=True)
    Creator = models.ForeignKey(UserDict, on_delete=models.CASCADE)  # 用户删除 本表关联数据也会删除
    CreateDatetime = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    class Meta:
        verbose_name=verbose_name_plural="用户下载记录"


#充值记录
class UserPayRecord(models.Model):
    ID = models.AutoField(primary_key=True)  # 自定义自增列
    PayMoney=models.DecimalField(verbose_name="支付金额",default=0,max_digits=9, decimal_places=2)
    status = models.CharField(max_length=20, verbose_name="成功标识", default="0")
    Creator = models.ForeignKey(UserDict, on_delete=models.CASCADE)  # 用户删除 本表关联数据也会删除
    CreateDatetime = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    class Meta:
        verbose_name=verbose_name_plural="用户充值记录"

#

